import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;


public class NodeSave {
	
	CustomButton save = new CustomButton("Spara");
	CustomButton cancel = new CustomButton("Avbryt");
	Player player;
	InterfaceFrame frame;
	

	NodeSave(final Player player, final InterfaceFrame frame){
		
		this.player = player;
		this.frame = frame;
		
		cancel.addMouseListener(new TheMouseListener());
		save.addMouseListener(new TheMouseListener());
		
		cancel.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				frame.nface.textArea.setText("");
				frame.nface.popOptions.removeAll();
				frame.getContentPane().repaint();
			}			
		});
		
		save.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				frame.nface.textArea.setText("Spelet är sparat");
				Profile.save(player, "newsave.xml");
				frame.nface.popPrime.show(frame, 50, 55);
			}
			
		});
	}
	
	public void show(){
		frame.nface.popOptions.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		frame.nface.textArea.setText("Vill du spara?");
		frame.nface.popOptions.add(save);
		frame.nface.popOptions.add(cancel);
	}
	
	class CustomButton extends JButton{
		
		private static final long serialVersionUID = 1L;
		
		CustomButton(String str){
			super(str);
			this.setContentAreaFilled(false);
			this.setForeground(Color.BLACK);
		}
		
		@Override
		public Dimension getMinimumSize(){
			return new Dimension(306,50);	
		}
		@Override
		public Dimension getMaximumSize(){
			return new Dimension(306,50);	
		}
		@Override
		public Dimension getPreferredSize(){
			return new Dimension(306,50);	
		}
		
	}
	
	private class TheMouseListener implements MouseListener{

		@Override
		public void mouseClicked(MouseEvent e){
		}

		@Override
		public void mouseEntered(MouseEvent e) {
		}

		@Override
		public void mouseExited(MouseEvent e) {
		}
		
		@Override
		public void mousePressed(MouseEvent e) {
			frame.nface.popPrime.show(frame, 50, 55);
		}

		@Override
		public void mouseReleased(MouseEvent e) {
			
		}
		
	}
	
}

